package com.example.kotlincomponent

import android.app.ActionBar
import android.os.Build
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.PopupWindowCompat
import kotlinx.android.synthetic.main.activity_popupwindow.*

class PopupWindowActivity:AppCompatActivity(), View.OnClickListener {
	override fun onCreate(savedInstanceState: Bundle?) {
		super.onCreate(savedInstanceState)
		setContentView(R.layout.activity_popupwindow)
		btn_popup.setOnClickListener(this)
	}

	@RequiresApi(Build.VERSION_CODES.KITKAT)
	override fun onClick(v: View?) {
//		TODO("Not yet implemented")
		when(v?.id){
			R.id.btn_popup->{
				val inflate = View.inflate(this, R.layout.pop_item, null)
				val popupWindow = PopupWindow(
					inflate, ViewGroup.LayoutParams.WRAP_CONTENT,
					ViewGroup.LayoutParams.WRAP_CONTENT
				)
				popupWindow.isOutsideTouchable=true
				popupWindow.showAsDropDown(findViewById(R.id.btn_popup),
				0,0,Gravity.RIGHT)
				val findViewById = inflate.findViewById<TextView>(R.id.tv_pop)
				findViewById.setOnClickListener(){v->popupWindow.dismiss()}
			}
		}
	}
}
